package com.javaee.rmi.demo;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

public class RmiClient {
	
	public static void main(String[] args) {
		
		try {
			
			String url = "rmi://localhost:1099/student";
			Object stu = Naming.lookup(url);
			System.out.println(stu.getClass().getName());
			
			/** 只能将其强转成远程对象的引用,而不是远程对象实现类*/
			RemoteStudent student = (RemoteStudent)stu;
			System.out.println(student.getClass().getName());
			
			String name = student.getNameById(1);
			System.out.println("name:"+name);
			
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (RemoteException e) {
			e.printStackTrace();
		} catch (NotBoundException e) {
			e.printStackTrace();
		}
	}
}
